package web.http;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.Date;

@WebServlet({"/HttpServletDemo","/xxx/*","/zz.do"})
public class HttpServletDemo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
        //1.获取请求路径
        String uri = request.getRequestURI();
        System.out.println(uri);
        //2.判断当前路径uri到底是哪种请求方式
        if(uri.equals("/Javaweb02_war_exploded/HttpServletDemo")){
            System.out.println("访问方式1");
        } else if (uri.equals("*.do")) {
            System.out.println("访问方式2");
        }else if (uri.equals("/Javaweb02_war_exploded/*")) {
            System.out.println("访问方式3");
        }else if (uri.equals("/Javaweb02_war_exploded/hi")) {
            System.out.println("访问方式4");
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.getWriter().write(new Date().toString());
    }
}
